<?php
/**
 * 针对recommend模块获取月份景点信息后，进行季节信息整合操作
 * @version $Id: month_data_merge_season.func.php 4631 2011-11-29 10:11:28Z guanghui1 $
 * @param array $data
 * @param bool $with_this_next_month 是否处理本月和下月的信息？默认为否（丢弃）
 * @return array
 */
function month_data_merge_season(array $data, $with_this_next_month = false){
	
	$return = array(
		1 => array( 
	    	'name' => '春季', 
	    	'search_key' => '1',
	    	'img_url' => '', 
	    	'ids' => array (),
		),
		2 => array( 
	    	'name' => '夏季', 
	    	'search_key' => '2',
	    	'img_url' => '', 
	    	'ids' => array (),
		),
		3 => array( 
	    	'name' => '秋季', 
	    	'search_key' => '3',
	    	'img_url' => '', 
	    	'ids' => array (),
		),
		4 => array( 
	    	'name' => '冬季', 
	    	'search_key' => '4',
	    	'img_url' => '', 
	    	'ids' => array (),
		),
	);
	
	$this_month = date('n');
	
	//先处理特殊数据：当月、下月
	if(true == $with_this_next_month){
		if(isset($data[74]) && is_array($data[74]) && !empty($data[74]['ids'])){
			$return[74] = $data[74];
			$return[74]['name'] = $this_month. '月';
			$return[74]['search_key'] = $this_month;
		}
		if(isset($data[75]) && is_array($data[75]) && !empty($data[75]['ids'])){
			$return[75] = $data[75];
			$_next_month = $this_month + 1;
			if($_next_month > 12){
				$_next_month = 1;
			}
			$return[75]['name'] = $_next_month. '月';
			$return[75]['search_key'] = $_next_month;
		}
	}
	unset($data[74], $data[75]);
	
	//剩余的1-12月份数据处理
	foreach($data as $block){
		/*
		 * 季度算法
		 * 目前如下规定：$season_month = array('1'=>'2,3,4','2'=>'5,6,7','3'=>'8,9,10','4'=>'11,12,1');
		 */
		$block_month = isset($block['search_key']) ? intval($block['search_key']) : 0;
		
		if($block_month <= 1 || $block_month > 12){
			$block_month = 13;    //1月认为是冬季
		}
		$season_id = intval(($block_month + 1) /3);
		
		$_season_block =& $return[$season_id];
		if(!empty($block['img_url'])){
			$_season_block['img_url'] = $block['img_url'];
		}
		
		if(!empty($block['ids'])){
			$_season_block['ids'] = array_merge($_season_block['ids'], $block['ids']);
		}
	}
	
	return $return;
}